package com.sanjiahantang.youjiarole.module.project.presenters;

import android.content.Context;

import com.sanjiahantang.youjiarole.base.BaseMvpActivity;
import com.sanjiahantang.youjiarole.base.BaseMvpPresenter;
import com.sanjiahantang.youjiarole.base.BaseView;
import com.sanjiahantang.youjiarole.base.CallBack;
import com.sanjiahantang.youjiarole.config.ConfigValue;
import com.sanjiahantang.youjiarole.config.SPConfig;
import com.sanjiahantang.youjiarole.module.me.scheme.beans.MeSchemeListBean;
import com.sanjiahantang.youjiarole.module.project.beans.ProjectInnerListResponseBean;
import com.sanjiahantang.youjiarole.module.project.beans.ProjectListResponseBean;
import com.sanjiahantang.youjiarole.module.project.models.IProjectModel;
import com.sanjiahantang.youjiarole.module.project.models.impl.ProjectModel;
import com.sanjiahantang.youjiarole.module.project.views.ProjectView;
import com.sanjiahantang.youjiarole.module.project.views.impl.ProjectActivity;
import com.sanjiahantang.youjiarole.module.project.views.impl.ProjectListFragment;
import com.sanjiahantang.youjiarole.utils.SPUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by zy on 2017/10/29.
 */

public class ProjectPresenter extends BaseMvpPresenter<ProjectView> {

    private IProjectModel projectModel;

    public ProjectPresenter(){
        projectModel = new ProjectModel();

    }
    public void loadProjectList(Context context, int pageType, final BaseView.OnLoadListener onLoadListener) {
        Map<String,Object> param = new HashMap<>();
        param.put(KEY_TOKEN, ConfigValue.DATA_KEY);
        param.put(KEY_PAGE,1);
        param.put(KEY_PAGE_SIZE,DEFAULT_PAGE_SIZE);
        Map<String,Object> map = new HashMap<>();
        map.put(KEY_PHONE, SPUtils.get(context, SPConfig.PHONE,"").toString());
        map.put("totalStateId",pageType);
        param.put(KEY_PARAM,map);
//        mView.showProgress();
        projectModel.loadProjectList(context,param, new CallBack<MeSchemeListBean>() {
            @Override
            public void onSuccess(MeSchemeListBean response, Context context, Object tag) {
                if (mView == null) return;
                mView.hideProgress();
                if (response == null || response.getCode() != RESPONSE_CODE_SUC) return;
                onLoadListener.onLoad(response.getData().getList());
            }

            @Override
            public void onFailure(String message) {
                if (mView == null) return;
                mView.hideProgress();
            }
        });
    }

    public void loadProjectInnerList(Context context, int id, final BaseView.OnLoadListener onLoadListener) {
        Map<String,Object> param = new HashMap<>();
        projectModel.loadProjectInnerList(context,param, new CallBack<ProjectInnerListResponseBean>() {
            @Override
            public void onSuccess(ProjectInnerListResponseBean response, Context context, Object tag) {
                onLoadListener.onLoad(tag);
            }

            @Override
            public void onFailure(String message) {

            }
        });
    }
}
